package com.bjpowernode.web.resp;

import com.bjpowernode.constants.enums.Code;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;

import java.io.Serializable;

/**
 * @author 麦翔盛
 * @ClassName: ResponseObj
 * @Package: com.bjpowernode.web.resp
 * @description: controller 响应类
 * @date 2022/5/14 22:16
 */
@ApiModel(value = "ResponseObj",description = "控制层响应类")
public class ResponseObj implements Serializable {

    @ApiModelProperty(value = "响应码")
    private Integer code;

    @ApiModelProperty(value = "返回信息")
    private String message;

    @ApiModelProperty(value = "返回数据")
    private Object content;

    public void setEnum(Code code){
        this.code = code.getCode();
        this.message = code.getMessage();
    }

    public ResponseObj(Code code) {
        setEnum(code);
    }

    /**
     * 成功
     * @return
     */
    public static ResponseObj ok(){
        return new ResponseObj(Code.REQUEST_SUCCESS);
    }

    public ResponseObj content(Object content){
        this.content = content;
        return this;
    }

    public ResponseObj message(String message){
        this.message = message;
        return this;
    }

    /**
     * 请求失败
     * @return
     */
    public static ResponseObj fail(){
        return new ResponseObj(Code.REQUEST_DEF_ERR);
    }

    /**
     * 异常 逻辑异常
     * @param code 应答码
     * @return
     */
    public static ResponseObj error(Code code){
        return new ResponseObj(code);
    }


    public ResponseObj(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResponseObj(Integer code) {
        this.code = code;
    }



    public ResponseObj(Integer code, String message, Object content) {
        this.code = code;
        this.message = message;
        this.content = content;
    }

    public ResponseObj() {
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getContent() {
        return content;
    }

    public void setContent(Object content) {
        this.content = content;
    }
}
